package com.project.fortuneteller.controller;


import com.project.fortuneteller.context.UserContext;
import com.project.fortuneteller.pojo.dto.MessageDto;
import com.project.fortuneteller.service.impl.MessageServiceImpl;
import com.project.fortuneteller.utils.Result;
import com.project.fortuneteller.utils.ThreeCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
@CrossOrigin
@RestController
@RequestMapping(("/message"))
public class MessageController {

    @Autowired
    private MessageServiceImpl messageService;

    /**
     * 获取用户聊天的历史
     * @param message
     * @return
     */
    @RequestMapping("/messageHistory")
    public Result getMessageHistory( @RequestBody MessageDto message) {
//        Integer userId =(Integer) ThreeCache.get(request.getHeader("authorization"));
        return messageService.getMessageHistory(Integer.parseInt(UserContext.getUserId()),message);
    }

    /**
     * 设置 消息 已读
     * @return
     */
    @RequestMapping("/setMessageStatus")
    public Result setNoReadMessage( @RequestBody MessageDto message) {

//        Integer userId =(Integer) ThreeCache.get(request.getHeader("authorization"));
        return Result.success(messageService.setNoReadMessage(Integer.parseInt(UserContext.getUserId()),message.getFriendId()));
    }



}
